<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/1/12
 * Time: 11:29
 */

include "../../config.php";
header("Content-type: text/html; charset=utf-8");

//关于森特->公司简介修改
if(!empty($_POST['agsjj']) && isset($_POST['agsjj'])){
    $class="公司简介";
    $text=!empty($_POST['text'])?$_POST['text']:null;
    $tableName="about";
    $sql="select * from {$tableName} where class = '{$class}'";
    $ret=$mysqli->query($sql);
    if($ret->num_rows>0){
        $sql="update about set text='{$text}' where class='{$class}'";
//        $ret=$mysqli->query($sql);
        if($mysqli->query($sql)){
            echo "<script> alert('更新成功');window.location.href='../about_gsjj.php'; </script>";
        }else{
            echo "<script> alert('更新失败');window.location.href='../about_gsjj.php'; </script>";
        }
    }else{
        $sql="insert into about value (null,'{$class}','{$text}')";
        if($mysqli->query($sql)){
            echo "<script> alert('添加成功');window.location.href='../about_gsjj.php'; </script>";
        }else{
            echo "<script> alert('添加失败');window.location.href='../about_gsjj.php'; </script>";
        }
    }
}

//关于森特->企业理念修改
elseif(!empty($_POST['aqyln']) && isset($_POST['aqyln'])){
    $class="企业理念";
    $text=!empty($_POST['text'])?$_POST['text']:null;
    $tableName="about";
    $sql="select * from {$tableName} where class = '{$class}'";
    $ret=$mysqli->query($sql);
    if($ret->num_rows>0){
        $sql="update about set text='{$text}' where class='{$class}'";
//        $ret=$mysqli->query($sql);
        if($mysqli->query($sql)){
            echo "<script> alert('更新成功');window.location.href='../about_qyln.php'; </script>";
        }else{
            echo "<script> alert('更新失败');window.location.href='../about_qyln.php'; </script>";
        }
    }else{
        $sql="insert into about value (null,'{$class}','{$text}')";
        if($mysqli->query($sql)){
            echo "<script> alert('添加成功');window.location.href='../about_qyln.php'; </script>";
        }else{
            echo "<script> alert('添加失败');window.location.href='../about_qyln.php'; </script>";
        }
    }
}

//关于森特->我们的荣誉修改
elseif(!empty($_POST['wmdry']) && isset($_POST['wmdry'])){
    $class="我们的荣誉";
    $text=!empty($_POST['text'])?$_POST['text']:null;
    $tableName="about";
    $sql="select * from {$tableName} where class = '{$class}'";
    $ret=$mysqli->query($sql);
    if($ret->num_rows>0){
        $sql="update about set text='{$text}' where class='{$class}'";
//        $ret=$mysqli->query($sql);
        if($mysqli->query($sql)){
            echo "<script> alert('更新成功');window.location.href='../wmdry.php'; </script>";
        }else{
            echo "<script> alert('更新失败');window.location.href='../wmdry.php'; </script>";
        }
    }else{
        $sql="insert into about value (null,'{$class}','{$text}')";
        if($mysqli->query($sql)){
            echo "<script> alert('添加成功');window.location.href='../wmdry.php'; </script>";
        }else{
            echo "<script> alert('添加失败');window.location.href='../wmdry.php'; </script>";
        }
    }
}

//关于森特->分支机构修改
elseif(!empty($_POST['fzjg']) && isset($_POST['fzjg'])){
    $class="分支机构";
    $text=!empty($_POST['text'])?$_POST['text']:null;
    $tableName="about";
    $sql="select * from {$tableName} where class = '{$class}'";
    $ret=$mysqli->query($sql);
    if($ret->num_rows>0){
        $sql="update about set text='{$text}' where class='{$class}'";
//        $ret=$mysqli->query($sql);
        if($mysqli->query($sql)){
            echo "<script> alert('更新成功');window.location.href='../fzjg.php'; </script>";
        }else{
            echo "<script> alert('更新失败');window.location.href='../fzjg.php'; </script>";
        }
    }else{
        $sql="insert into about value (null,'{$class}','{$text}')";
        if($mysqli->query($sql)){
            echo "<script> alert('添加成功');window.location.href='../fzjg.php'; </script>";
        }else{
            echo "<script> alert('添加失败');window.location.href='../fzjg.php'; </script>";
        }
    }
}

//关于森特->公司地址修改
elseif(!empty($_POST['gsdz']) && isset($_POST['gsdz'])){
    $class="公司地址";
    $text=!empty($_POST['text'])?$_POST['text']:null;
    $tableName="about";
    $sql="select * from {$tableName} where class = '{$class}'";
    $ret=$mysqli->query($sql);
    if($ret->num_rows>0){
        $sql="update about set text='{$text}' where class='{$class}'";
//        $ret=$mysqli->query($sql);
        if($mysqli->query($sql)){
            echo "<script> alert('更新成功');window.location.href='../gsdz.php'; </script>";
        }else{
            echo "<script> alert('更新失败');window.location.href='../gsdz.php'; </script>";
        }
    }else{
        $sql="insert into about value (null,'{$class}','{$text}')";
        if($mysqli->query($sql)){
            echo "<script> alert('添加成功');window.location.href='../gsdz.php'; </script>";
        }else{
            echo "<script> alert('添加失败');window.location.href='../gsdz.php'; </script>";
        }
    }
}